﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNH_DAL_WS
{
    public class Ultilities
    {
        //lay ma so ke tiep
        public static string GetNextId(string lastID, string type)
        {
            RestaurantManagementDataContext data = new RestaurantManagementDataContext();

            var code = (from prefix in data.CODEs
                           where prefix.Data.Equals(type)
                           select prefix).First();

            string ID = code.Prefix;

            string tmp = lastID;
            tmp = tmp.Remove(0, code.Prefix.Length);
            int id = Int32.Parse(tmp);
            id++;
            int len = Int32.Parse(code.PostfixLength.ToString()) - id.ToString().Length;
            for (int i = 0; i < len; i++)
            {
                ID += "0";
            }

            ID += id.ToString();
            return ID;
        }

        //kiem tra co ton tai 1 chuoi trong chuoi nao do
        public static bool IsContainsString(String source, String toCheck, StringComparison comp)
        {
            return source.IndexOf(toCheck, comp) >= 0;
        }
    }
}